package com.qidian.mes.md.controller;


import com.qidian.mes.md.service.MdWorkShopService;
import com.qidian.mes.pojo.MdWorkShop;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @Time 2023/10/24 14:23
 * @Description
 */
@RestController
@RequestMapping("/workshop")
@CrossOrigin
public class MdWorkShopController {
    @Autowired
    private MdWorkShopService mdWorkShopService;

    /**
     * 新增车间弹窗中自动生成车间编码
     * @return
     */
    @RequestMapping("/generateWorkShopCode")
    public MESResult gen(){
        return mdWorkShopService.generateWorkShopCode();
    }
    /**
     * 多条件分页查询车间
     * @param page
     * @param limit
     * @param mdWorkShop
     * @return
     */
    @GetMapping("/list")
    public MESResult list(@RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10") int limit, MdWorkShop mdWorkShop){
        System.out.println(mdWorkShop);
        return mdWorkShopService.list(page,limit,mdWorkShop);
    }
    @GetMapping("/get")
    public MESResult get(Long workshopId){

        return mdWorkShopService.get(workshopId);
    };

    /**
     *新增车间
     * @param mdWorkShop
     * @return
     */
    @PostMapping("/save")
    public MESResult save(@RequestBody MdWorkShop mdWorkShop) {
        return mdWorkShopService.save(mdWorkShop);
    }

    /**
     * 根据id删除单个车间
     * @param workshopId
     * @return
     */
    @DeleteMapping("/delete")
    public MESResult delete(Long workshopId){
//        System.out.println("**-*-*-*-*-*-*-*-*-"+dictId);
        return mdWorkShopService.delete(workshopId);
    }

    /**
     * 批量删除车间
     * @param workshopId
     * @return
     */
    @DeleteMapping("/deletes")
    public MESResult deletes(Long[] workshopId){
        return mdWorkShopService.deletes(workshopId);
    }

    /**
     * 修改车间
     * @param mdWorkShop
     * @return
     */
    @PutMapping("/update")
    public MESResult update(@RequestBody MdWorkShop mdWorkShop){
//        System.out.println("***-**-*-*-*-*-*"+dict);
        return mdWorkShopService.update(mdWorkShop);
    }
}
